/**
 * @param {number} capacity
 */
var LRUCache = function(capacity) {
    this.capacity = capacity;
    this.cache = new Map();
};

/**
 * @param {number} key
 * @return {number}
 */
LRUCache.prototype.get = function(key) {
    let temp;
    if(this.cache.has(key)){
        temp = this.cache.get(key);
        this.cache.delete(key);
        this.cache.set(key, temp);
    }

    return temp ?? -1;
};

/**
 * @param {number} key
 * @param {number} value
 * @return {void}
 */
LRUCache.prototype.put = function(key, value) {
    if(this.cache.has(key)){
        this.cache.delete(key);
    }
    this.cache.set(key, value);
    if(this.cache.size > this.capacity){
        this.cache.delete(this.cache.keys().next().value);
    }
};
